package com.daur.uva.input;

import java.util.ArrayList;
import java.util.List;

public class InputReader {

	public InputMatrix createInputMatrix(String firstLine) {
		Integer[] baseNumbers = getIntegersFromLine(firstLine);
		return new InputMatrix(baseNumbers[0], baseNumbers[1]);
	}

	public void updateInputMatrix(InputMatrix inputMatrix, int boxNumber, String line) {
		Integer[] sizes = getIntegersFromLine(line);
		inputMatrix.addNewBox(boxNumber, sizes);
	}

	private Integer[] getIntegersFromLine(String line) {
		List<Integer> numbers = new ArrayList<Integer>();
		for (String each : line.trim().split("\\s+")) {
			numbers.add(new Integer(each));
		}
		return numbers.toArray(new Integer[] {});
	}

}
